import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    num:10,
    score:100,
    t:1000,
    a:10000,
    b:1,
    cityList:[],
    cityList2:[1,2,3,4,5],
  },
  mutations: {
    add(state,payload){
      state.num+=payload;
    },
    addCityList(state,payload){
      state.cityList=payload;
    }
  },
  actions: {
    getCityList(context,payload){
      // console.log(context);
      // console.log(payload);
      let arr=['a','b','c'];
      setTimeout(() => {
        context.commit('addCityList',arr);
      }, 1000);
    }
  },
  getters: {
    CityListLen(state,getters){
      return state.cityList.length;
    },
    CityListLen2(state,getters){
      console.log(getters);
      return state.cityList2.length;
    }
  },
  modules: {
  },
  plugins: [createPersistedState()]
})
